package cc.jt.cc;

import java.util.concurrent.ThreadPoolExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ThreadPoolMonitor {

  private static final Logger logger = LoggerFactory.getLogger(ThreadPoolMonitor.class);

  private ThreadPoolExecutor executor;

  private String name;

  public ThreadPoolMonitor(String name, ThreadPoolExecutor threadPoolExecutor) {
    this.name = name;
    this.executor = threadPoolExecutor;
  }


  public void log() {
//            int getCorePoolSize()：核心线程数，Tag：thread.pool.core.size。
//            int getLargestPoolSize()：历史峰值线程数，Tag：thread.pool.largest.size。
//            int getMaximumPoolSize()：最大线程数(线程池线程容量)，Tag：thread.pool.max.size。
//            int getActiveCount()：当前活跃线程数，Tag：thread.pool.active.size。
//            int getPoolSize()：当前线程池中运行的线程总数(包括核心线程和非核心线程)，Tag：thread.pool.thread.count。
//            getQueue().size() 当前任务队列中积压任务的总数
    logger.info(
        "poolName={}: activeSize={}, coreSize={}, maxSize={}, queueSize={}, largestPoolSize={}, remainingCapacity={}, poolSize={}",
        name, executor.getActiveCount(), executor.getCorePoolSize(), executor.getMaximumPoolSize(),
        executor.getQueue().size(), executor.getLargestPoolSize(), executor.getQueue().remainingCapacity(),
        executor.getPoolSize());

  }
}
